
public class RotateArray {

	public static int arr[]= {1,2,3,4,5,6,7};
	
	public static void leftRotate(int d)
	{
	  d--;
	  reverse (0,d);
	  reverse (d+1,arr.length -1);
	  reverse (0,arr.length - 1);
	}

	public static void rightRotate(int d)
	{
	  d--;
	  int n = arr.length - 1;
	  reverse (n-d,n);
	  reverse (0,n-d-1);
	  reverse (0,arr.length - 1);
	}

	public static void printArray()
	{
	  int i;
	  for(i = 0; i < arr.length; i++)
	    System.out.print(arr[i]+" ");
	  System.out.println();
	} 
	
	public static void reverse(int start,int end)
	{
		int mid = start + ((end - start)/2);
		while(start <= mid) {
			int temp =arr[start];
			arr[start] = arr[end];
			arr[end] = temp;
			end--;
			start++;
		}
		
	 }    
	public static void main(String[] args) {
		// TODO Auto-generated method stub
printArray();
leftRotate(2);
printArray();
rightRotate(2);
printArray();
	}

}
